package com.jckj.core.service.impl;

import com.jckj.core.dao.UserNotifyMapper;
import com.jckj.core.entity.UserNotify;
import com.jckj.core.entity.UserNotifyExample;
import com.jckj.core.exception.ServiceException;
import com.jckj.core.service.UserNotifyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *     用户通知服务实现类
 * </p>
 * @author:liukuan
 * @date :2018-01-29
 */
@Service
@Transactional(readOnly = true,rollbackFor = ServiceException.class)
public class UserNotifyServiceImpl implements UserNotifyService {

    private static Logger LOGGER = LoggerFactory.getLogger(UserNotifyServiceImpl.class);


    @Autowired
    private UserNotifyMapper userNotifyMapper;


    @Override
    @Transactional(readOnly = false,rollbackFor = ServiceException.class)
    public int insert(UserNotify userNotify) {
        int num=0;
        try {
              num= userNotifyMapper.insertSelective(userNotify);
        }catch(Exception ex){
            LOGGER.error("增加内部科室:%s", ex.fillInStackTrace());
            throw new ServiceException("添加用户信息出错",ex);
        }
        return num;
    }

    @Override
    @Transactional(readOnly = false,rollbackFor = ServiceException.class)
    public int updateByNotifyId(UserNotify userNotify,String id) {
        int num=0;
        try {
            UserNotifyExample example=new UserNotifyExample();
            UserNotifyExample.Criteria criteria = example.createCriteria();
            criteria.andNotifyIdEqualTo(id);
            num=userNotifyMapper.updateByExampleSelective(userNotify,example);
        } catch (Exception e) {
            LOGGER.error("修改内部科室:%s", e.fillInStackTrace());
            throw new ServiceException("修改用户通知出错",e);
        }

        return num;
    }

    @Override
    @Transactional(readOnly = false,rollbackFor = ServiceException.class)
    public int deleteByNotifyId(String id) {
        int num=0;
        try {
            UserNotifyExample example=new UserNotifyExample();
            UserNotifyExample.Criteria criteria = example.createCriteria();
            criteria.andNotifyIdEqualTo(id);
            num= userNotifyMapper.deleteByExample(example) ;
        } catch (Exception e) {
            LOGGER.error("删除内部科室:%s", e.fillInStackTrace());
            throw new ServiceException("删除用户通知出错",e);
        }
           return num;
    }


}
